from research.calcor import calcor_base

class nhnl_r(calcor_base):
    def __init__(self,timeperiod=250,mintimeperiod=None):
        super().__init__(timeperiod=timeperiod,mintimeperiod=mintimeperiod,datatype="dim1")
    def calc(self):
        p0=max(self.hisdata)
        p1 = min(self.hisdata)
        p2=self.hisdata[-1]
        r0 = (p2 - p1) / p1
        r1 = (p2 - p0) / p0
        return r0, r1
class nhnl_r_bybar(calcor_base):
    def __init__(self, timeperiod=250, mintimeperiod=None):
        super().__init__(timeperiod=timeperiod, mintimeperiod=mintimeperiod, datatype="bar", inputs=["high","low","close"])
    def calc(self):
        p0 = max(self.hisdata["high"])
        p1 = min(self.hisdata["low"])
        p2 = self.hisdata["close"][-1]
        r0 = (p2-p1)/p1
        r1 = (p2-p0)/p0
        return r0,r1
